package com.automannn.websoketmqtt.provider.config;
import com.automannn.websoketmqtt.common.amqp.DirectGlobalValue;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author chenkh
 * @time 2020/10/12 16:40
 */
@Configuration
public class DirectRabbitConfig {



    /**
     * 队列配置
     * @return
     */
    @Bean
    public Queue automannnQueue(){
        return new Queue(DirectGlobalValue.QUEUE_NAME,true);
    }

    /**
     * 直连交换机配置
     * @return
     */
   public DirectExchange automannnExchange(){
        return new DirectExchange(DirectGlobalValue.EXCHANGE_NAME,true,false);
    }

    /**
     * 绑定交互机与队列，并给定 路由键
     */
    @Bean
    public Binding bindingDirect(){
        return BindingBuilder.bind(automannnQueue()).to(automannnExchange()).with(DirectGlobalValue.ROUTING_KEY);
    }

    @Bean
    public DirectExchange testExchange(){
        return new DirectExchange("testExchagne");
    }
}
